package com.thrd.taiexhibition.fresco;

import android.content.Context;
import android.graphics.Matrix;
import android.util.AttributeSet;

import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.drawable.ScalingUtils;
import com.facebook.drawee.generic.GenericDraweeHierarchy;
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
import com.facebook.drawee.interfaces.DraweeController;
import com.facebook.drawee.view.SimpleDraweeView;
import com.thrd.taiexhibition.R;

/**
 * 自定义iMAGE
 */
public class FrescoImage extends SimpleDraweeView {
    public FrescoImage(Context context, GenericDraweeHierarchy hierarchy) {
        super(context, hierarchy);
        initView();
    }

    public FrescoImage(Context context) {
        super(context);
        initView();
    }

    public FrescoImage(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView();
    }

    public FrescoImage(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        initView();
    }

    public FrescoImage(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);

        initView();
    }

    private void initView(){
//        mGenericDraweeHierarchy.setPlaceholderImage(R.drawable.system_image_placeholder);
//        mGenericDraweeHierarchy.setRetryImage(R.drawable.system_image_error);
        GenericDraweeHierarchy hierarchy = new GenericDraweeHierarchyBuilder(getResources())
                //淡入淡出动画持续时间(单位：毫秒ms)
                .setFadeDuration(300)
                // 重试图
                .setRetryImage(R.drawable.system_image_placeholder)
                //失败图
                .setFailureImage(R.drawable.system_image_error)
                //重试图的缩放类型
                .setRetryImageScaleType(ScalingUtils.ScaleType.FIT_CENTER)
                //占位图的缩放类型
                .setPlaceholderImageScaleType(ScalingUtils.ScaleType.FIT_CENTER)
                //失败图的缩放类型
                .setFailureImageScaleType(ScalingUtils.ScaleType.FIT_CENTER)
                //实际图像的缩放类型
                .setActualImageScaleType(ScalingUtils.ScaleType.CENTER_CROP)

                .build();

        DraweeController controller= Fresco.newDraweeControllerBuilder()
                .setTapToRetryEnabled(true)
                .build();

        setController(controller);
        this.setHierarchy(hierarchy);
    }

    public void animateTransform(Matrix matrix) {
        invalidate();
    }




}
